<?php

namespace Ruben\Aliyun;

use Mts\Request\V20140618\QueryMediaListByURLRequest;
use Mts\Request\V20140618\QueryMediaListRequest;


class Mts
{
    private $vhost;
    private $appName;
    private $privateKey;
    private $accessKey;
    private $accessSecret;
    private $regionId;

    public function __construct($config)
    {
        $this->vhost = $config['host'];
        $this->appName = $config['app_name'];
        $this->accessKey = $config['access_key_id'];
        $this->accessSecret = $config['access_key_secret'];
        $this->privateKey = $config['private_key'];
        $this->regionId = $config['region_id']?:'cn-shenzhen';
        
    }

    public function queryMediaListByURL($ossUrl)
    {
        require('aliyun-openapi-php-sdk/aliyun-php-sdk-core/Config.php');
        \Autoloader::addAutoloadPath('aliyun-php-sdk-mts');
        $iClientProfile = \DefaultProfile::getProfile($this->regionId, $this->accessKey, $this->accessSecret);
        $client = new \DefaultAcsClient($iClientProfile);
        $request = new QueryMediaListByURLRequest();
        $request->setFileURLs($ossUrl);
        $response = $client->getAcsResponse($request);
        return $response;
    }

    /**
     * 根据mediaId查询媒体库
     *
     * @param string $mediaId
     * @return void
     */
    public function queryMediaList($mediaId)
    {
        require('aliyun-openapi-php-sdk/aliyun-php-sdk-core/Config.php');
        \Autoloader::addAutoloadPath('aliyun-php-sdk-mts');
        $iClientProfile = \DefaultProfile::getProfile($this->regionId, $this->accessKey, $this->accessSecret);
        $client = new \DefaultAcsClient($iClientProfile);
        $request = new QueryMediaListRequest();
        $request->setMediaIds($mediaId);
        $response = $client->getAcsResponse($request);
        return $response;
    }


}
